<template>
  <h2>添加会员权益</h2>
  <table class="table-bordered" border="1">
    <tr>
      <td>权益名称</td>
      <td>
        <input
          type="text"
          placeholder="请输入权益名称"
          v-model="Right.mR_Name"
        />
      </td>
    </tr>
    <tr>
      <td>权益说明</td>
      <td>
        <textarea
          name=""
          placeholder="请输入权益名称"
          v-model="Right.mR_Info"
        ></textarea>
      </td>
    </tr>
    <tr>
      <td>是否自定义:</td>
      <td>
        <input type="radio" value="是" v-model="Right.mR_IsCustom" />是
        <input type="radio" value="否" v-model="Right.mR_IsCustom" />否
      </td>
    </tr>
    <tr>
      <td>规则类型</td>
      <td>
        <input type="radio" :value="0" v-model="Right.mR_RuleType" />折扣
        <input type="radio" :value="1" v-model="Right.mR_RuleType" />餐饮
        <input type="radio" :value="2" v-model="Right.mR_RuleType" />延时
      </td>
    </tr>
    <tr>
      <td>权益规则</td>
      <td>
        <textarea
          placeholder="请输入权益规则"
          v-model="Right.mR_Rule"
        ></textarea>
      </td>
    </tr>
    <tr>
      <td colspan="2" style="text-align: center">
        <input type="button" value="修改" @click="UpMemberRights" />
      </td>
    </tr>
  </table>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import axios from "axios";

import { useRoute } from "vue-router";
import { error } from "console";

const route = useRoute();
// 创建响应式数据
const Right = ref({
  mR_Id: 0,
  mR_Name: "",
  mR_Info: "",
  mR_IsCustom: "",
  mR_RuleType: 0,
  mR_Rule: "",
});

onMounted(() => {
  UpsqlMemberRights();
});
const UpsqlMemberRights = () => {
  axios
    .get("https://localhost:7071/api/MemberRights/UpSqlMemberRights", {
      params: {
        MRId: route.query.id,
      },
    })
    .then((res) => {
      console.log(res.data);
      Right.value = res.data;
    })
    .catch((err) => {
      console.log(err);
    });
};

const UpMemberRights = () => {
    axios.put('https://localhost:7071/api/MemberRights/UpMemberRights', Right.value)
    .then((res) => {
      console.log(res.data);
      alert("修改成功");
    })
 
        .catch(error => {
            console.log(error);
    })
}
</script>

<style scoped>
</style>